import { Body, Controller, Get, Param, Post } from '@nestjs/common';
import { PrismaService } from 'src/prisma/prisma.service';

@Controller('script')
export class ScriptController {
    constructor(
        private readonly prismaService: PrismaService
    ) { }

    @Get(":id/get")
    async get(
        @Param("id") debug_id: string
    ) {
        const result = await this.prismaService.line.findFirst({
            where: {
                debug_id
            }
        });
        if (!!result) {
            console.log("检测到重复数据-", result);
        }
        return !!result ? result : "{}";
    }

    @Get(":id/set/:data")
    async set(
        @Param("id") debug_id: string,
        @Param("data") data: string
    ) {
        console.log(data)
        // const data = body.data;
        if (!!await this.prismaService.line.findFirst({ where: { debug_id } })) {
            return await this.prismaService.line.update({
                where: { debug_id },
                data: { data }
            })
        }
        return this.prismaService.line.create({
            data: {
                debug_id,
                data
            }
        })
    }
}
